<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	if(!$_RQ['id']){
		exi('请先选择酒店！','error','jy_jd/index/');
	}
	$settime=$this->session('settime');
	$return['hotel']=pdo_get('jy_jd_hotel',array('id'=>$_RQ['id']));	
	if(!$return['hotel']['status']){
		exi('该酒店已下架！','error','jy_jd/index/');
	}
	$return['hotel']['images']=json_decode($return['hotel']['images'],true);
	$return['hotel']['lat_lng']=json_decode($return['hotel']['lat_lng'],true);
	if($return['hotel']['images']){
		$return['imagenum']=count($return['hotel']['images']);
	}
	$return['hotel']['mobile2']=$return['hotel']['mobile']?cfc('tools')->substr($return['hotel']['mobile'],0,7).'****':'';
	$return['hotel']['tel2']=$return['hotel']['tel']?cfc('tools')->substr($return['hotel']['tel'],0,7).'****':'';
	$return['room']=pdo_getall('jy_jd_room',array('hotelid'=>$_RQ['id'],'status'=>1),'','','display desc');
	foreach($return['room'] as &$v){
		$v['taocan']=json_decode($v['taocan'],true);
		$v['taocan']=$this->model('model')->get_uptaocan($v);
		$v['images']=json_decode($v['images'],true);
		if(!$v['images'][0]){
			$v['images'][0]=$v['image'];
		}
		paixu($v['taocan'],'price');
		$v['price']=$this->model('model')->get_nowprice($v);
		$innum=$this->model('model')->get_innum($v,$settime['intime']);
		$roomdaynum=$this->model('model')->getroomdaynum($v,$settime['intime']);
		$v['unin']=$roomdaynum-$innum;
	}
	$id=$_RQ['id'];
	$return['juli']=$_SESSION['juli'][$id];
	$return['time']=$return['juli']*2;
	$return['showlist']='goods';
	$return['commentsnum']=pdo_count('jy_jd_comments',array('hotelid'=>$_RQ['id'],'status'=>1));
	$return['commentsfen'] = $this->model('model')->count_comments($_RQ['id']);
	$return['post']=array(
		'day'=>$settime['day']?:1,
		'intime'=>$settime['intime']?:date("Y-m-d"),
		'endtime'=>$settime['endtime']?:date("Y-m-d",strtotime("+1 day")),
	);
	$return['post']['settime']=array(
			'tstart'=>strtotime($return['post']['intime']),
			'tend'=>strtotime($return['post']['endtime']),
	);
	$sharelink='jy_jd/hotel//id='.$_RQ['id'].'&fromuser='.$_SESSION['uid'];
	$return['sharedata']=array(
		'title'=>$return['hotel']['title']?:'首页-在线酒店',
		'desc'=>$return['hotel']['desc']?:'在线酒店，一个属于旅行之家！',
		'link'=>custom_url($sharelink,true),
		'imgUrl'=>tomedia($return['hotel']['image'])
	);
	set_html('title',$return['hotel']['title']);
	exi($return);
}
if($_RQ['op']=='getcomments'){
	$hotelid=$_RQ['hotelid']?intval($_RQ['hotelid']):$_SESSION['hotelid'];
	$params=array('hotelid'=>$hotelid,'status'=>1);
	$parameter['orderby']=array('star desc','id desc');
	$type=$_RQ['type'];
	if($type=='percent'){
			$params['star']=5;
	}
	if($type=='normal_percent'){
			$params['star']=array(2,3,4);
	}
	if($type=='bad_percent'){
			$params['star']=array(0,1);
	}
	if($type=='pic'){
			$params['images !=']='';
	}
	if($type=='new'){
			$parameter['orderby']=array('createtime desc','star desc');
	}
	$parameter['params']=$params;
	$pindex = max(1, intval($page));
	$psize = $limit?:5;
	$parameter['limit']=array($pindex,$psize);
	$list=$this->pdo_getlist('comments',$parameter,$total);
	if($list){
			foreach($list as &$item){
				$item['member']=model('core/member')->detail($item['mid'],array('nickname','avatar'));
				$item['member']['nickname']=$item['member']['nickname']?:'匿名用户';
				$item['images']=$item['images']?json_decode($item['images'],true):array();
				$item['room']=pdo_get('jy_jd_room',array('id'=>$item['goodsid']));
				$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='getjuli'){
	$hotel=pdo_get('jy_jd_hotel',array('id'=>$_RQ['id']));
	$hotel['lat_lng']=json_decode($hotel['lat_lng'],true);
	if($_RQ['lat'] || $_RQ['lng']){
		$lat_lng=array('lat'=>$_RQ['lat'],'lng'=>$_RQ['lng']);
	}
	$juli=cfc('tools')->getdistance($lat_lng['lng'],$lat_lng['lat'],$hotel['lat_lng']['lng'],$hotel['lat_lng']['lat']);
	$return['juli']=intval($juli/1000);
	$return['time']=$return['juli']*2;
	exi($return);
}